// 二叉树最近公共祖先
var lowestCommonAncestor = function(root, p, q) {
    /*let ans = 0;
   function dfs(root,p,q) {
       if(root == null) return false;
       const l = dfs(root.left,p,q);
       const r = dfs(root.right,p,q);
       if((l&&r)||((root.val==p.val||root.val==q.val)&&(l||r)) ){
           ans = root;
       }
       return l || r || (root.val == p.val || root.val == q.val);
   }
   dfs(root,p,q);
   return ans;*/
   if(root==null || root.val == p.val || root.val == q.val) {
       return root;
   }
   let l = lowestCommonAncestor(root.left,p,q);
   let r = lowestCommonAncestor(root.right,p,q);
   if(l&&r) {
       return root;
   }
   return l?l:r
};